package com.company.OfferGuide;

public class 股票的最大利润 {

    public static void main(String[] args) {
        System.out.println(maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }


    public static int maxProfit(int[] prices) {
        if (prices == null || prices.length <= 1) return 0;
        int[] dp = new int[prices.length];
        dp[1] = 0;
        int minValue = prices[0];
        for (int i = 1; i < dp.length; i++) {
            dp[i] = Math.max(dp[i - 1],prices[i] - minValue);
            minValue = Math.min(prices[i],minValue);
        }

        return dp[prices.length - 1];

    }

}
